package org.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.chen.dto.TtsModelDTO;
import org.chen.entity.TtsModel;
import org.chen.mapper.TtsModelMapper;
import org.chen.service.TtsModelService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TtsModelServiceImpl extends ServiceImpl<TtsModelMapper, TtsModel> implements TtsModelService {

    @Autowired
    private TtsModelMapper ttsModelMapper;

    @Override
    public List<TtsModelDTO> getAllModels() {
        List<TtsModel> models = ttsModelMapper.selectList(null);
        return models.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    @Override
    public TtsModelDTO getModelById(String modelId) {
        QueryWrapper<TtsModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("model_id", modelId);
        TtsModel model = ttsModelMapper.selectOne(queryWrapper);
        return model != null ? convertToDTO(model) : null;
    }

    private TtsModelDTO convertToDTO(TtsModel model) {
        TtsModelDTO dto = new TtsModelDTO();
        dto.setId(model.getModelId());
        dto.setName(model.getName());
        dto.setDescription(model.getDescription());
        return dto;
    }
}